package com.im.gate.server;


import com.rou.im.framework.core.Request;
import com.rou.im.framework.core.processorstack.ProcessorStack;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 * @since 2020-04-06 16:01
 */
@ChannelHandler.Sharable
@Component
public class ServerMessageHandler extends SimpleChannelInboundHandler<Request> {

    @Autowired
    ProcessorStack processorStack;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        // 注册信息
        super.channelActive(ctx);
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Request msg) throws Exception {

        //  触发获取到Response事件
        processorStack.stack(msg);
        //clientMsgProcessor.process(ctx,msg.getMsg());
    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
      /*  Long userId = ctx.channel().attr(UserIdAttributeKey.USER_ID).get();
        Session.destroyedByUserId(userId);*/
        cause.printStackTrace();
    }



  /*  class ClientMsgProcessor extends AbstractIMProcessor<Class<? extends Msg>,Msg> {
        @Override
        public void registryProcessor() {
            registry(ChatMsg.class, (ctx, msg) -> cmd.doChatForward(ctx, msg));
            registry(AckMsg.class, (ctx, msg) -> cmd.doSendReceiptAck(ctx, msg));
            registry(ClientMsg.class, (ctx, msg) -> cmd.doLogin(ctx, msg));
        }
    }*/
}
